﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Home.Master" Inherits="System.Web.Mvc.ViewPage<ArticleInputModels>" %>

<%@ Import Namespace="SDT.Lib.Paging" %>
<%@ Import Namespace="SDT.Lib" %>
<%@ Import Namespace="SDT.Site.ViewModels" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Gửi bài viết
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<script src="/tiny_mce/tiny_mce.js" type="text/javascript"></script>
<link href="/Content/rounded.css" rel="stylesheet" type="text/css" />
    
 <div class="contact" id="element-box" style="margin-top:7px">
		<div class="t">
			<div class="t">
				<div class="t"></div>
			</div>
		</div>
		<div class="m">
			<h2>GỬI BÀI ViẾT ĐỂ MỌI NGƯỜI CÙNG CHIA SẺ VỚI BẠN</h2>
			<%=ViewData["MessageInfo"]!=null? "<p class='perror'>"+Html.Encode(ViewData["MessageInfo"])+"</p>":string.Empty%>
			<form method=post action="/readers/create" name="siteForm" id="siteForm" enctype = "multipart/form-data">
			<table cellpadding="0" cellspacing="0" class="contactForm">
				<tbody>
					<tr>
						<td><label for="Article.Title">Tiêu đề</label></td>
						<td>
							<%= Html.TextBoxFor(m=>m.Article.Title, new { @class = "required", style="width:500px" })%>
						</td>
					</tr>
					<tr>
						<td><label for="ImagePath">Ảnh đại diện (<font color="red">*</font>)</label>:</td>
						<td>
							<input type="file" name="ImagePath" id="ImagePath" value="" />
						</td>
					</tr>
					<tr>
						<td><label for="Article.ArticleContent">Nội dung (<font color="red">*</font>)</label>:</td>
						<td>
							<%= Html.TextAreaFor(m=>m.Article.ArticleContent, new { style = "height: 324px; width:500px" })%>
						</td>
					</tr>
					<tr>
						<td><label for="Article.Title">Chuyên mục đăng bài</label></td>
						<td>
							<%= Html.DropDownList("ddlCategory",new SelectList(Model.Category.ArticleCategories,"ID","Name"), new { @class = "required", style="width:300px" })%>
						</td>
					</tr>
					<tr>
						<td><label for="name">Tag</label></td>
						<td>
							<%= Html.TextBox("TagName", string.Empty, new { style = "width:500px" })%><br />
                            <%= Html.Hidden("TagID")%> (<font color="red">*</font>)Cho phép chọn nhiều tag, mỗi tag cách nhau bằng dấu ","
						</td>
					</tr>
					<tr>
						<td><label for="name"> Nhập mã xác thực&nbsp;(<font style="color:Red">*</font>)</label></td>
						<td>
							<%= Html.TextBox("CaptchaText", string.Empty, new { @class = "required" })%>&nbsp;<img id="captchaImg" name="captchaImg" src="/AjaxData/ShowCaptchaImage" style="vertical-align:middle; height:30px" />
						</td>
					</tr>
					<tr>
						<td align="center" colspan="2">
							<input type="submit" value="Gửi" />
						</td>
					</tr>
				</tbody>
			</table>
			</form>
		</div>
		<div class="b">
			<div class="b">
				<div class="b"></div>
			</div>
		</div>
	</div>
<script type="text/javascript">
    $(document).ready(function() {
        $("#siteForm").validate({
            rules: {
                "Article.Title": "required",
                ddlCategory: "required"
            },
            messages: {
                "Article.Title": "Trường này là bắt buộc, vui lòng nhập dữ liệu!",
                ddlCategory: "Trường này là bắt buộc, vui lòng chọn dữ liệu!"
            }
        });
        
        $("#TagName").autocomplete({
            minLength: 2,
            source: function(request, response) {
                $.ajax({
                    url: "/AjaxData/SearchTag",
                    dataType: "json",
                    data: {
                        keyword: extractLast(request.term)
                    },
                    success: function(data) {
                        response($.map(data, function(item) {
                            return {
                                label: item.Keyword,
                                value: item.Keyword,
                                id: item.ID
                            }
                        }));
                    }
                });
            },
            focus: function() {
                // prevent value inserted on focus
                return false;
            },
            select: function(event, ui) {
                var terms = split(this.value);
                // remove the current input
                terms.pop();
                // add the selected item
                terms.push(ui.item.value);
                // add placeholder to get the comma-and-space at the end
                terms.push("");
                this.value = terms.join(", ");

                var termsk = split($('#TagID').val());
                // remove the current input
                termsk.pop();
                // add the selected item
                termsk.push(ui.item.id);
                // add placeholder to get the comma-and-space at the end
                termsk.push("");
                $('#TagID').val(termsk.join(","));
                return false;
            }
        });
    });    
    tinyMCE.init({
        mode: "exact",
        plugins: "paste,imagemanager",
        theme: "advanced",
        elements: "Article_ArticleContent",
        theme_advanced_buttons1: "pastetext,separator,bold,italic,underline,separator,strikethrough,justifyleft,justifycenter,justifyright, justifyfull,bullist,numlist,undo,redo,link,unlink",
        theme_advanced_buttons2: "",
        theme_advanced_buttons3: "",
        theme_advanced_toolbar_location: "top",
        theme_advanced_toolbar_align: "left",
        theme_advanced_statusbar_location: "bottom",
        paste_use_dialog: false,
        paste_auto_cleanup_on_paste: true,
        paste_convert_headers_to_strong: false,
        paste_strip_class_attributes: "all",
        paste_remove_spans: true,
        paste_remove_styles: true
    });
    </script>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="RightContent" runat="server">
<% Html.RenderAction("Focus", "Readers", new { number = 5, skip = 0, catid = Model.Category != null ? Model.Category.ID : SDT.Model.ConfigManager.GetArticle(), title = "Bài xem nhiều", order = "nViews", orderDir = "desc" }); %>
<div class="clear"></div>
<% Html.RenderAction("NewestByCat", "Article", new { number = 3, skip = 0, catid = SDT.Model.ConfigManager.GetChuyengiaPhantich(), title = "Chuyên gia phân tích", order = "ID", orderDir = "desc" }); %>
</asp:Content>
